﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Ninject;
using Meraz.Core.Managers;
using Meraz.Web.Models;
using Meraz.Core.Model;
using Meraz.Core.Providers;
using System.Web.Security;
using Meraz.Web.Models.Home;
using Meraz.Web.Models.Admin;

namespace Meraz.Web.Controllers
{
    [HandleError]
    public class HomeController : Controller
    {

        [Inject]
        public BlogManager BlogManager { get; set; }
        public ActionResult Index()
        {
            ViewData["Menu"] = Menu.Home;
            IndexModel model = new IndexModel();
            if (HttpContext.User.Identity.IsAuthenticated)
            {
                string username = HttpContext.User.Identity.Name;
                MembershipUser user = Membership.GetUser(username, true);
                model.Username = username;
                model.Email = user.Email;
                model.Roles = String.Join(", ", Roles.GetRolesForUser());
            }
            return View(model);
        }

        [HttpPost]
        public ActionResult Index(IndexModel model)
        {
            System.Diagnostics.Trace.WriteLine("login");
            System.Diagnostics.Trace.WriteLine("login", "test category");
            ViewData["Menu"] = Menu.Home;
            string username = HttpContext.User.Identity.Name;
            MembershipUser user = Membership.GetUser(username, true);
            user.Email = model.Email;
            Membership.UpdateUser(user);
            model.Roles = String.Join(", ", Roles.GetRolesForUser());
            model.NewPassword = string.Empty;
            model.OldPassword = string.Empty;
            model.ConfirmPassword = string.Empty;
            return View(model);
        }

        public ActionResult ResetPassword()
        {
            return View("NotImplemented");
            //ViewData["Menu"] = Menu.Home;
            //return View();
        }

        [HttpPost]
        public ActionResult ResetPassword(string Username)
        {
            return View("NotImplemented");

            //if (string.IsNullOrWhiteSpace(Username))
            //    throw new ApplicationException("Valid username required!");
            //MembershipUser user = Membership.GetUser(Username);
            //return View();
        }

        public ActionResult About()
        {
            return View();
        }
        public ActionResult NotAuth()
        {
            return View();
        }
    }
}
